package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ChannelConcurrent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "CIDConcurrentMapper")
public interface CIDConcurrentMapper extends BaseMapper<ChannelConcurrent> {

    @Select("<script> " +
            "SELECT * FROM  " +
            "(SELECT Date,CID " +
            ",sum(hour00) as hour00,sum(hour01) as hour01,sum(hour02) as hour02,sum(hour03) as hour03,sum(hour04) as hour04,sum(hour05) as hour05 " +
            ",sum(hour06) as hour06,sum(hour07) as hour07,sum(hour08) as hour08,sum(hour09) as hour09,sum(hour10) as hour10,sum(hour11) as hour11 " +
            ",sum(hour12) as hour12,sum(hour13) as hour13,sum(hour14) as hour14,sum(hour15) as hour15,sum(hour16) as hour16,sum(hour17) as hour17 " +
            ",sum(hour18) as hour18,sum(hour19) as hour19,sum(hour20) as hour20,sum(hour21) as hour21,sum(hour22) as hour22,sum(hour23) as hour23 " +
            "FROM VodConcurrent${Date} " +
            "WHERE CID = #{CID} " +
            "GROUP BY Date,CID) a " +
            "JOIN " +
            "(SELECT * FROM CIDInformation ) b " +
            "ON a.CID = b.CID "+
            "</script>")
    List<Map<String, Object>> CIDConcurrentAll(@Param("Date") String Date,@Param("CID") String CID);


    @Select("<script> " +
            "SELECT DISTINCT Area FROM " +
            "(SELECT * FROM VodConcurrent${Date} WHERE CID = #{CID} )a " +
            "JOIN " +
            "(SELECT IP,Area FROM HMSInformation) b  " +
            "ON a.IP = b.IP "+
            "</script>")
    List<Map<String, Object>> CIDConcurrentArea(@Param("Date") String Date,@Param("CID") String CID);

    @Select("<script> " +
            "SELECT * FROM ( " +
            "SELECT Date,CID,Area  " +
            ",sum(hour00) as hour00,sum(hour01) as hour01,sum(hour02) as hour02,sum(hour03) as hour03,sum(hour04) as hour04,sum(hour05) as hour05   " +
            ",sum(hour06) as hour06,sum(hour07) as hour07,sum(hour08) as hour08,sum(hour09) as hour09,sum(hour10) as hour10,sum(hour11) as hour11   " +
            ",sum(hour12) as hour12,sum(hour13) as hour13,sum(hour14) as hour14,sum(hour15) as hour15,sum(hour16) as hour16,sum(hour17) as hour17  " +
            ",sum(hour18) as hour18,sum(hour19) as hour19,sum(hour20) as hour20,sum(hour21) as hour21,sum(hour22) as hour22,sum(hour23) as hour23 " +
            "FROM " +
            "(SELECT * FROM VodConcurrent${Date} WHERE CID = #{CID} )a " +
            "JOIN " +
            " (SELECT IP,Area FROM HMSInformation WHERE Area=#{Area} ) b " +
            "ON a.IP = b.IP " +
            "GROUP BY Date,CID,Area)c " +
            "JOIN   " +
            "(SELECT * FROM CIDInformation ) d " +
            "ON c.CID = d.CID "+
            "</script>")
    List<Map<String, Object>> CIDConcurrentByArea(@Param("Date") String Date,@Param("CID") String CID,@Param("Area") String Area);
}
